<template>
	<view>

		<view class="addUserInfo" @click="targetBasicInfo">
			<view v-if="!appUserInfo" class="else">
				<image src="https://new.kuxia.top/uploads/image/20220930/129569cc7f0ea54ea6724e4a4ccdddf0.png" />
				<text>完善用户信息</text>
			</view>
			<view v-if="appUserInfo" class="if">
				<view>{{ appUserInfo.name }}</view>
				<view>
					<view>{{ appUserInfo.tel }}</view>
					<view>
						<text>详情</text>
						<image
							src="https://new.kuxia.top/uploads/image/20220930/42db1de5be8eddef523c822197a648fa.png" />
					</view>
				</view>
			</view>
		</view>

		<view class="row">
			<view class="list" @click="targetMyReserve">
				<view>
					<image src="https://new.kuxia.top/uploads/image/20220930/2de6ad961dc5002310745f42a7e520d7.png" />
					<text>我的预约</text>
				</view>
				<image src="https://new.kuxia.top/uploads/image/20220930/42db1de5be8eddef523c822197a648fa.png" />
			</view>
			<view class="hr"></view>
			<view class="list" @click="targetPaymentDetails">
				<view>
					<image src="https://new.kuxia.top/uploads/image/20220930/2de6ad961dc5002310745f42a7e520d7.png" />
					<text>住院记录</text>
				</view>
				<image src="https://new.kuxia.top/uploads/image/20220930/42db1de5be8eddef523c822197a648fa.png" />
			</view>
			<view class="hr"></view>

		</view>

		<u-overlay :show="loading">
			<view style="height:100%;display:grid;place-content:center;">
				<u-loading-icon text="加载中..." textSize="18" color="#fff" textColor="#fff" :vertical="true">
				</u-loading-icon>
			</view>
		</u-overlay>

	</view>
</template>

<script>
const App = getApp();
import {
	getUserInfo
} from '../../request/index.js'
export default {
	data() {
		return {
			appUserInfo: '',
			loading: false,
		}
	},
	onShow() {
		const that = this;
		that.getAppUserInfo((success) => {
			if (!success) {
				uni.showModal({
					title: '提示',
					content: '请授权登录',
					success: function (res) {
						if (res.confirm) {
							that.globalAutr(() => {
								console.log("yes:", uni.getStorageSync('userid'));
								getUserInfo({ uid: uni.getStorageSync('userid') }).then(res => {
									if (res.data.status == 2) {
										uni.showModal({
											title: '',
											content: '',
											success: function (res) {
												if (res.confirm) {
													uni.navigateTo({
														url: '/pages/basiclnfo/index'
													})
												} else if (res.cancel) {

												}
											}
										})
									}
								})
							})
						} else if (res.cancel) {
							uni.switchTab({
								url: '/pages/index/index'
							})
						}
					}
				});
			}
		});
	},
	onLoad() {


	},
	methods: {
		targetPaymentDetails() {
			this.globalAutr(() => {
				uni.navigateTo({
					url: '/pages/paymentDetails/index'
				})
			})
		},
		targetMyReserve() {
			this.globalAutr(() => {
				uni.navigateTo({
					url: '/pages/myReserve/index'
				})
			})
		},
		targetBasicInfo() {
			this.globalAutr(() => {
				uni.navigateTo({
					url: '/pages/basicInfo/index'
				})
			})
		},
		getAppUserInfo(resolve = () => { }) {
			getUserInfo({
				uid: uni.getStorageSync('userid'),
			}).then(res => {
				console.log(res.data);
				if (res.data.status) {
					this.appUserInfo = res.data.info;
					resolve(true)
				} else {
					resolve(false)
				}
			})
		},
		globalAutr(resolve, reject = () => { }) {
			App.autr(() => {
				resolve()
			}, () => {
				reject()
			}, (loadingStatus) => {
				console.log(loadingStatus);
				this.loading = loadingStatus;
			}, () => {
				this.getAppUserInfo();
			})
		}
	},
}
</script>

<style lang="scss">
.addUserInfo {
	width: 100%;
	margin: 0 auto;
	height: 25vh;
	background-color: #28da70;
	display: flex;

	>.if {
		width: 100%;
		padding: 7vh 4.5% 7vh 25%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		>view {
			&:first-child {
				font-size: 22px;
			}

			&:last-child {
				display: flex;
				justify-content: space-between;

				>view:first-child {
					font-size: 14px;

					&::before {
						content: '手机号：';
						font-size: 16px;
					}
				}

				>view:last-child {
					display: flex;
					align-items: center;

					>text {
						transform: translateX(.35em);
						font-size: 16px;
					}

					>image {
						height: 80%;
						width: 1em;
					}
				}
			}
		}
	}

	>.else {
		display: flex;
		align-items: center;
		margin: auto;

		>image {
			width: 7vw;
			height: 6vw;
			margin-right: .5vw;
		}

		>text {
			color: white;
			font-size: 17px;
		}
	}
}

.row {

	width: 100%;
	padding: 0 4%;
	box-sizing: border-box;

	>.list {
		width: 100%;
		display: flex;
		justify-content: space-between;
		padding: 2vh 3vw;
		box-sizing: border-box;
		align-items: center;

		>view {
			display: flex;
			align-items: center;

			>image {
				width: 35px;
				height: 35px;
				margin: 0 5vw 0 auto;
				background-color: #1677ff;
				padding: 2.5px;
				box-sizing: border-box;
				border-radius: 50%;
			}

			>text {
				font-size: 17px;
			}
		}

		>image {
			width: 7vw;
			height: 7vw;
		}
	}

	>.hr {
		height: 1px;
		background: #d6d7d9;
		width: 100%;
		transform: scaleY(.5);
	}
}
</style>
